//
//  ZTimeOutOrderUntreatedVC.m
//  DistributorAB
//
//  Created by LZY on 2019/10/16.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZTimeOutOrderUntreatedVC.h"
#import "ZTimeOutOrderDetailPersonCell.h"
#import "ZTimeOutOrderDetailElectricCell.h"
#import "ZTimeOutOrderTreatingVC.h"//处理中

@interface ZTimeOutOrderUntreatedVC () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation ZTimeOutOrderUntreatedVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (AGENT_LEVEL == 1) {
        if ([self.orderModel.delstate isEqualToString:@"0"]) {
            self.title = @"未处理";
        }else if ([self.orderModel.delstate isEqualToString:@"1"]){
            self.title = @"处理中";
        }else if ([self.orderModel.delstate isEqualToString:@"2"]){
            self.title = @"已处理";
        }
    }else{
        self.title = @"未处理";        
    }
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = kColorWithHex(0xf2f2f2);
    
    [self setupViewAction];
}
#pragma mark - 界面布局
- (void)setupViewAction{
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNaviHeight, kScreen_Width, kScreen_Height - kNaviHeight) style:UITableViewStylePlain];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = kColorWithHex(0xf2f2f2);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    _tableView.estimatedRowHeight = 300;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[ZTimeOutOrderDetailPersonCell class] forCellReuseIdentifier:NSStringFromClass([ZTimeOutOrderDetailPersonCell class])];
    [_tableView registerClass:[ZTimeOutOrderDetailElectricCell class] forCellReuseIdentifier:NSStringFromClass([ZTimeOutOrderDetailElectricCell class])];
    
    if (AGENT_LEVEL != 1) {
        //市县级
        UIButton *btnGo = [UIButton buttonWithType:UIButtonTypeCustom];
        [btnGo setTitle:@"去处理" forState:UIControlStateNormal];
        [btnGo setTitleColor:kColorWithHex(0xffffff) forState:UIControlStateNormal];
        [btnGo setBackgroundColor:kColorWithHex(0x70be68)];
        btnGo.titleLabel.font = [UIFont systemFontOfSize:16];
        btnGo.layer.cornerRadius = 4;
        btnGo.layer.masksToBounds = YES;
        [btnGo addTarget:self action:@selector(btnGoClickAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btnGo];
        [btnGo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view.mas_centerX);
            make.bottom.equalTo(self.view.mas_bottom).offset(-kScaleNum(29) - TabbarSafeBottomMargin);
            make.size.mas_equalTo(CGSizeMake(kScaleNum(319), 48));
        }];
    }
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //个人家庭 、 电器厂
    if ([self.orderModel.user_type isEqualToString:@"0"]) {
        ZTimeOutOrderDetailPersonCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZTimeOutOrderDetailPersonCell class]) forIndexPath:indexPath];
        [cell setupBViewAction];
        cell.orderModel = self.orderModel;
        return cell;
    }else if ([self.orderModel.user_type isEqualToString:@"2"]){
        ZTimeOutOrderDetailElectricCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZTimeOutOrderDetailElectricCell class]) forIndexPath:indexPath];
        [cell setupBViewAction];
        cell.orderModel = self.orderModel;
        return cell;
    }else{
        return [UITableViewCell new];
    }
    
}
#pragma mark - UITableViewDelegate

#pragma mark - 交互事件
- (void)btnGoClickAction:(UIButton *)sender{
    kWeakSelf;
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    [param setObjectIfNotNil:self.orderModel.Id forKey:@"id"];
    [NetWorkTool POST:USER_DEL_OVERTIME param:param success:^(id dic) {
        ZTimeOutOrderTreatingVC *vc = [ZTimeOutOrderTreatingVC new];
        vc.orderID = weakSelf.orderModel.Id;
        [weakSelf.navigationController pushViewController:vc animated:YES];
        [[NSNotificationCenter defaultCenter] postNotificationName:USER_DEAL_TIME_OUT_ORDER_SUCCESS object:nil];
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
    } needUser:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
